$(function(){
	
	 $('.register-form').validate({
            errorElement: 'span', //default input error message container
            errorClass: 'help-block', // default input error message class
            focusInvalid: false, // do not focus the last invalid input
            ignore: "",
            rules: {
                
                regusername: {
                    required: true
                },
                reguserpassword: {
                    required: true,
                    minlength:6
                },
                rpassword: {
                	required: true,
                    minlength:6,
                    equalTo: "#reguserpassword"
                },
				verificationCode: {
                    required: true,
                    minlength:6
               }
            },

            messages: { 
            	regusername:"用户账号不能为空",
            	reguserpassword:{
							required: "用户密码不能为空",
							minlength:"密码长度不能小于6"
				},
				rpassword:{
					required: "用户确认密码不能为空",
					minlength:"密码长度不能小于6",
					equalTo:"密码和确认密码不一致"
				},
				verificationCode: {
                    required: "验证码不能为空"
               }
            },

            invalidHandler: function(event, validator) { //display error alert on form submit   

            },

            highlight: function(element) { // hightlight error inputs
                $(element)
                    .closest('.form-group').addClass('has-error'); // set error class to the control group
            },

            success: function(label) {
                label.closest('.form-group').removeClass('has-error');
                label.remove();
            },

            errorPlacement: function(error, element) {
                if (element.attr("name") == "tnc") { // insert checkbox errors after the container                  
                    error.insertAfter($('#register_tnc_error'));
                } else if (element.closest('.input-icon').size() === 1) {
                    error.insertAfter(element.closest('.input-icon'));
                } else {
                    error.insertAfter(element);
                }
            },

            submitHandler: function(form) {
                //form.submit();
                alert("ok");
           
            }
        });

        $('.register-form input').keypress(function(e) {
            if (e.which == 13) {
                if ($('.register-form').validate().form()) {
                    $('.register-form').submit();
                }
                return false;
            }
        });

        jQuery('#register-btn').click(function() {
            jQuery('.login-form').hide();
            jQuery('.infomation-form').hide();
            jQuery('.register-form').show();
            jQuery('.forget-form').hide();
        });

        jQuery('#register-next-btn').click(function() {
            jQuery('.login-form').hide();
            jQuery('.infomation-form').show();
            jQuery('.register-form').hide();
            jQuery('.forget-form').hide();
        });
        
        jQuery('#register-back-btn').click(function() {
            jQuery('.login-form').show();
            jQuery('.register-form').hide();
        });
	
		jQuery('#register-last-btn').click(function() {
			jQuery('.infomation-form').hide();
			jQuery('.register-form').show();
		})
		
		jQuery('#forget-password').click(function() {
			jQuery('.login-form').hide();
			jQuery('.forget-form').show();
		})
		
		jQuery('#forget-back-btn').click(function() {
			jQuery('.login-form').show();
			jQuery('.forget-form').hide();
		})
})

